package com.longshihan.carservice.service.order;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.longshihan.carservice.dao.GoodsDao;
import com.longshihan.carservice.dao.OrderDao;
import com.longshihan.carservice.model.LogDomain;
import com.longshihan.carservice.model.OrderDomain;
import com.longshihan.carservice.model.OrderGoodsDomain;
import com.longshihan.carservice.utils.GsonUtils;
import com.longshihan.carservice.utils.UUID;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderServiceImpl implements OrderService {

    @Autowired
    private OrderDao orderDao;

    @Autowired
    private GoodsDao goodsDao;


    @Override
    public int createOrder(String userId, OrderDomain orderDomain) {
        String orderId= UUID.UU64();
        return orderDao.createOrder(orderId,userId,orderDomain.getGoods(),
                orderDomain.getNote(),orderDomain.getAddress(),
                orderDomain.getDeliverTime());
    }

    @Override
    public OrderDomain getOrderGoods(String orderId) {
        return orderDao.getUserOrderGoods(orderId);
    }

    @Override
    public PageInfo<OrderDomain> getUserOrder(String userId, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<OrderDomain> logs = orderDao.getUserOrder(userId);
        PageInfo<OrderDomain> pageInfo = new PageInfo<>(logs);
        return pageInfo;
    }


}
